package appp;

import java.util.ArrayList;

public class Stack {

    private ArrayList a;
    private int i;

    public Stack() {
        a = new ArrayList();
        this.i = 0;
    }

    public ArrayList getA() {
        return a;
    }

    public void setA(ArrayList a) {
        this.a = a;
    }

    public void push(Object o) {

        a.add(i, o);
        i++;
    }

    public boolean hasNext(){
        if (i<=0) return false; else return true;
    }
    
    public Object pop() {
        if (i <= 0) {
            return "Err";
        }
        Object o = a.get(i - 1);
        a.remove(i - 1);
        i--;
        return o;
    }

    @Override
    public String toString() {
        String result = "";
        for (int j = 0; j < a.size(); j++) {
            result += a.get(j) + ", ";
        }
        return result;
    }
}
